package f;

import c.b.a.a.a;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Nullable;

/* compiled from: MediaType */
public final class t {
    public static final Pattern d = Pattern.compile("([a-zA-Z0-9-!#$%&'*+.^_`{|}~]+)/([a-zA-Z0-9-!#$%&'*+.^_`{|}~]+)");
    public static final Pattern e = Pattern.compile(";\\s*(?:([a-zA-Z0-9-!#$%&'*+.^_`{|}~]+)=(?:([a-zA-Z0-9-!#$%&'*+.^_`{|}~]+)|\"([^\"]*)\"))?");
    public final String a;
    public final String b;
    @Nullable
    public final String c;

    public t(String str, String str2, String str3, @Nullable String str4) {
        this.a = str;
        this.b = str2;
        this.c = str4;
    }

    public static t a(String str) {
        Matcher matcher = d.matcher(str);
        if (matcher.lookingAt()) {
            String group = matcher.group(1);
            Locale locale = Locale.US;
            group = group.toLowerCase(locale);
            String toLowerCase = matcher.group(2).toLowerCase(locale);
            String str2 = null;
            Matcher matcher2 = e.matcher(str);
            int end = matcher.end();
            while (end < str.length()) {
                matcher2.region(end, str.length());
                String str3 = "\" for: \"";
                StringBuilder stringBuilder;
                if (matcher2.lookingAt()) {
                    String group2 = matcher2.group(1);
                    if (group2 != null && group2.equalsIgnoreCase("charset")) {
                        group2 = matcher2.group(2);
                        if (group2 != null) {
                            String str4 = "'";
                            if (group2.startsWith(str4) && group2.endsWith(str4) && group2.length() > 2) {
                                group2 = group2.substring(1, group2.length() - 1);
                            }
                        } else {
                            group2 = matcher2.group(3);
                        }
                        if (str2 == null || group2.equalsIgnoreCase(str2)) {
                            str2 = group2;
                        } else {
                            stringBuilder = new StringBuilder();
                            stringBuilder.append("Multiple charsets defined: \"");
                            stringBuilder.append(str2);
                            stringBuilder.append("\" and: \"");
                            stringBuilder.append(group2);
                            stringBuilder.append(str3);
                            stringBuilder.append(str);
                            stringBuilder.append('\"');
                            throw new IllegalArgumentException(stringBuilder.toString());
                        }
                    }
                    end = matcher2.end();
                } else {
                    stringBuilder = a.g("Parameter is not formatted correctly: \"");
                    stringBuilder.append(str.substring(end));
                    stringBuilder.append(str3);
                    stringBuilder.append(str);
                    stringBuilder.append('\"');
                    throw new IllegalArgumentException(stringBuilder.toString());
                }
            }
            return new t(str, group, toLowerCase, str2);
        }
        StringBuilder stringBuilder2 = new StringBuilder();
        stringBuilder2.append("No subtype found for: \"");
        stringBuilder2.append(str);
        stringBuilder2.append('\"');
        throw new IllegalArgumentException(stringBuilder2.toString());
    }

    @Nullable
    public static t b(String str) {
        try {
            return a(str);
        } catch (IllegalArgumentException unused) {
            return null;
        }
    }

    public boolean equals(@Nullable Object obj) {
        return (obj instanceof t) && ((t) obj).a.equals(this.a);
    }

    public int hashCode() {
        return this.a.hashCode();
    }

    public String toString() {
        return this.a;
    }
}
